<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="报送码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztsendno">
              <a-input v-model="model.ztsendno" placeholder="请输入报送码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="中文名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztcnname">
              <a-input v-model="model.ztcnname" placeholder="请输入中文名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="INCI名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztenname">
              <a-input v-model="model.ztenname" placeholder="请输入INCI名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztstatus">
              <a-input v-model="model.ztstatus" placeholder="请输入状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztprodcode">
              <a-input v-model="model.ztprodcode" placeholder="请输入生产代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="使用目的" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zttarget">
              <a-input v-model="model.zttarget" placeholder="请输入使用目的"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="等同原料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztequalmat">
              <a-input v-model="model.ztequalmat" placeholder="请输入等同原料"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="外观性状" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztappearance">
              <a-input v-model="model.ztappearance" placeholder="请输入外观性状"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产商*" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztbrand">
              <a-input v-model="model.ztbrand" placeholder="请输入生产商*"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="供应商" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztsupplier">
              <a-input v-model="model.ztsupplier" placeholder="请输入供应商"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属工厂" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztfactory">
              <a-input v-model="model.ztfactory" placeholder="请输入所属工厂"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产地" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztorigin">
              <a-input v-model="model.ztorigin" placeholder="请输入产地"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="价格（元/kg)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztprice">
              <a-input-number v-model="model.ztprice" placeholder="请输入价格（元/kg)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="通用性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztcommon">
              <a-input v-model="model.ztcommon" placeholder="请输入通用性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注（通用性）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztcommonrem">
              <a-input v-model="model.ztcommonrem" placeholder="请输入备注（通用性）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="包装材质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztpackmat">
              <a-input v-model="model.ztpackmat" placeholder="请输入包装材质"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最小包装（kg)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztpackmin">
              <a-input-number v-model="model.ztpackmin" placeholder="请输入最小包装（kg)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最小起订量（kg)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztordermin">
              <a-input-number v-model="model.ztordermin" placeholder="请输入最小起订量（kg)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="供货周期（天）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztsupplycycle">
              <a-input v-model="model.ztsupplycycle" placeholder="请输入供货周期（天）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="其他" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztother">
              <a-input v-model="model.ztother" placeholder="请输入其他"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="稳定性等级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztstability">
              <a-input v-model="model.ztstability" placeholder="请输入稳定性等级"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="微生物敏感等级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztsensible">
              <a-input v-model="model.ztsensible" placeholder="请输入微生物敏感等级"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="保质期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztquqntity">
              <a-input v-model="model.ztquqntity" placeholder="请输入保质期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="储存条件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztstore">
              <a-input v-model="model.ztstore" placeholder="请输入储存条件"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开封后储存条件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztopenstore">
              <a-input v-model="model.ztopenstore" placeholder="请输入开封后储存条件"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="注意事项" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztcaution">
              <a-input v-model="model.ztcaution" placeholder="请输入注意事项"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="使用要求" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztuserequire">
              <a-input v-model="model.ztuserequire" placeholder="请输入使用要求"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="急性毒性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztviru">
              <a-input v-model="model.ztviru" placeholder="请输入急性毒性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="刺激性/腐蚀性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztcj">
              <a-input v-model="model.ztcj" placeholder="请输入刺激性/腐蚀性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="致敏性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztzm">
              <a-input v-model="model.ztzm" placeholder="请输入致敏性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="光毒性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgt">
              <a-input v-model="model.ztgt" placeholder="请输入光毒性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="光变态反应" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgbt">
              <a-input v-model="model.ztgbt" placeholder="请输入光变态反应"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="致突变性/遗传毒性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztycdx">
              <a-input v-model="model.ztycdx" placeholder="请输入致突变性/遗传毒性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="重复剂量毒性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztcfjldx">
              <a-input v-model="model.ztcfjldx" placeholder="请输入重复剂量毒性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生殖发育毒性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztszfytx">
              <a-input v-model="model.ztszfytx" placeholder="请输入生殖发育毒性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="慢性毒性/致癌性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztmxdx">
              <a-input v-model="model.ztmxdx" placeholder="请输入慢性毒性/致癌性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="毒代动力学" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztdddlx">
              <a-input v-model="model.ztdddlx" placeholder="请输入毒代动力学"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="人体试验" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztrtsy">
              <a-input v-model="model.ztrtsy" placeholder="请输入人体试验"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="其他" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztothers">
              <a-input v-model="model.ztothers" placeholder="请输入其他"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="适用范围" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgxuserange">
              <a-input v-model="model.ztgxuserange" placeholder="请输入适用范围"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="使用限制" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgxuselimit">
              <a-input v-model="model.ztgxuselimit" placeholder="请输入使用限制"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="推荐用量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztjsreyl">
              <a-input v-model="model.ztjsreyl" placeholder="请输入推荐用量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="原料类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjmatclass">
              <a-input v-model="model.ztxjmatclass" placeholder="请输入原料类别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="香精级别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjclass">
              <a-input v-model="model.ztxjclass" placeholder="请输入香精级别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="气味" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjsmell">
              <a-input v-model="model.ztxjsmell" placeholder="请输入气味"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="提取工艺" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjprocess">
              <a-input v-model="model.ztxjprocess" placeholder="请输入提取工艺"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="灵感来源" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjinspire">
              <a-input v-model="model.ztxjinspire" placeholder="请输入灵感来源"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="香精科技" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjscience">
              <a-input v-model="model.ztxjscience" placeholder="请输入香精科技"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="应用类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjapptype">
              <a-input v-model="model.ztxjapptype" placeholder="请输入应用类别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="稳定性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjstable">
              <a-input v-model="model.ztxjstable" placeholder="请输入稳定性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="天然成分（%）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjcomponent">
              <a-input v-model="model.ztxjcomponent" placeholder="请输入天然成分（%）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="主成分" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjmaincf">
              <a-input v-model="model.ztxjmaincf" placeholder="请输入主成分"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="香气描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjdesc">
              <a-input v-model="model.ztxjdesc" placeholder="请输入香气描述"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="消费者描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjzfzdesc">
              <a-input v-model="model.ztxjzfzdesc" placeholder="请输入消费者描述"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="适用性别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjsytype">
              <a-input v-model="model.ztxjsytype" placeholder="请输入适用性别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="功效" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjgx">
              <a-input v-model="model.ztxjgx" placeholder="请输入功效"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="数据来源" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjsjly">
              <a-input v-model="model.ztxjsjly" placeholder="请输入数据来源"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="功效数据" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjgxdata">
              <a-input v-model="model.ztxjgxdata" placeholder="请输入功效数据"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="权威认证" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztxjqwrz">
              <a-input v-model="model.ztxjqwrz" placeholder="请输入权威认证"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="IFRA版本" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztifra">
              <a-input v-model="model.ztifra" placeholder="请输入IFRA版本"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="功效" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgxeffect">
              <a-input v-model="model.ztgxeffect" placeholder="请输入功效"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="数据来源" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgxdatasource">
              <a-input v-model="model.ztgxdatasource" placeholder="请输入数据来源"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="测试浓度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgxtestthick">
              <a-input v-model="model.ztgxtestthick" placeholder="请输入测试浓度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="测试结果" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgxtestresult">
              <a-input v-model="model.ztgxtestresult" placeholder="请输入测试结果"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="其他" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgxother">
              <a-input v-model="model.ztgxother" placeholder="请输入其他"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生物学靶点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgxbiological">
              <a-input v-model="model.ztgxbiological" placeholder="请输入生物学靶点"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="科技背书" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgxkjbs">
              <a-input v-model="model.ztgxkjbs" placeholder="请输入科技背书"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="适用范围" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgxuseranges">
              <a-input v-model="model.ztgxuseranges" placeholder="请输入适用范围"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="使用限制" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgxuselimits">
              <a-input v-model="model.ztgxuselimits" placeholder="请输入使用限制"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="推荐用量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgxtjquantity">
              <a-input v-model="model.ztgxtjquantity" placeholder="请输入推荐用量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="竞品信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgxcompet">
              <a-input v-model="model.ztgxcompet" placeholder="请输入竞品信息"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'MatrevbaseForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           ztcnname: [
              { required: true, message: '请输入中文名称!'},
           ],
           ztenname: [
              { required: true, message: '请输入INCI名称!'},
           ],
        },
        url: {
          add: "/roles/matrevbase/add",
          edit: "/roles/matrevbase/edit",
          queryById: "/roles/matrevbase/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>